﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Forest.Lion.Domain.Contracts;
using Forest.Lion.Model;

namespace Forest.Lion.Domain.Models
{
    public static class ViewModelExtensions
    {
        public static int? GetArgs(this DateTime? birthDay)
        {
            if (!birthDay.HasValue)
            {
                return null;
            }

            var temp = DateTime.Now - birthDay.Value;
            return (int)Math.Floor(temp.Days / 365.0);
        }


        public static Company ConvertToEntity(this IRegisterFormModel registerForm)
        {
            if (registerForm == null)
                return null;

            var company = new Company
            {
                Id = registerForm.Id,
                CompanyName = registerForm.CompanyName,
                Contact = registerForm.Contact,
                Tel = registerForm.Tel,
                Mobile = registerForm.Mobile,
                UserName = registerForm.UserName,
                Password = registerForm.Password
            };

            return company;
        }

        public static Company ConvertoToEntity(this ICompanyFormModel formModel)
        {
            if (formModel == null)
                return null;

            var company = new Company
            {
                Id = formModel.Id,
                CompanyName = formModel.CompanyName,
                //AnotherName = formModel.AnotherName,
                ShortName = formModel.ShortName,
                Shortcut = formModel.Shortcut,
                Industry = formModel.Industry,
                CompanyType = formModel.CompanyType,
                Employees = formModel.Employees,
                BusinessLicense = formModel.BusinessLicense,
                RegisteredCapital = formModel.RegisteredCapital,
                EstablishedOn = formModel.EstablishedOn,
                Overview = formModel.Overview,
                Business = formModel.Business,
                Province = formModel.Province,
                City = formModel.City,
                Address = formModel.Address,
                PostalCode = formModel.PostalCode,
                Contact = formModel.Contact,
                Tel = formModel.Tel,
                Fax = formModel.Fax,
                Mobile = formModel.Mobile,
                Email = formModel.Email,
                WebSite = formModel.WebSite,
                Park = formModel.Park,
                // IsGroup = formModel.IsGroup,
                // ParentCompanyId = formModel.ParentCompanyId,
                EnableShortName = formModel.EnableShortName,
                // EnableAnotherName = formModel.EnableAnotherName,
                //DailySigned = formModel.DailySigned,
                TemplateId = formModel.TemplateId,
                // UserName = formModel.UserName,
                //Password = formModel.Password,
                //PasswordSalt = formModel.PasswordSalt,
                //DateCreated = formModel.DateCreated,
                //CreatedBy = formModel.CreatedBy,
                LastUpdated = DateTime.Now,
                //ModifiedBy = formModel.ModifiedBy,
                // OwningUser = formModel.OwningUser
            };

            return company;

        }

        public static JobPosition ConvertToEntity(this IJobPositionFormModel formModel, JobPosition jobPosition = null)
        {
            if (formModel == null)
                return null;

            jobPosition = jobPosition ?? new JobPosition();
            jobPosition.Id = formModel.Id;
            jobPosition.JobTitle = formModel.JobTitle;
            jobPosition.Category = formModel.Category;
            jobPosition.JobType = formModel.JobType;
            jobPosition.DepartmentId = formModel.DepartmentId;
            jobPosition.UseDepartmentAddress = formModel.UseDepartmentAddress;
            jobPosition.Wants = formModel.Wants;
            jobPosition.Location = formModel.Location;
            jobPosition.Responsibilities = formModel.Responsibilities;
            jobPosition.Major = formModel.Major;
            jobPosition.EducationLevel = formModel.EducationLevel;
            jobPosition.YearsOfExperience = formModel.YearsOfExperience;
            jobPosition.Language = formModel.Language;
            jobPosition.LanguageLevel = formModel.LanguageLevel;
            jobPosition.MinAge = formModel.MinAge;
            jobPosition.MaxAge = formModel.MaxAge;
            jobPosition.Gender = formModel.Gender;
            jobPosition.Qualifications = formModel.Qualifications;
            jobPosition.SalaryRange = formModel.SalaryRange;
            jobPosition.MonthlySalary = formModel.MonthlySalary;
            jobPosition.IsOpenSalaryRange = formModel.IsOpenSalaryRange;
            jobPosition.Welfare = formModel.Welfare;
            jobPosition.Contact = formModel.Contact;
            jobPosition.Tel = formModel.Tel;
            jobPosition.Fax = formModel.Fax;
            jobPosition.Email = formModel.Email;
            jobPosition.IsReceivedEmail = formModel.IsReceivedEmail;
            jobPosition.Address = formModel.Address;
            jobPosition.PostalCode = formModel.PostalCode;
            jobPosition.SortOrder = formModel.SortOrder;
            jobPosition.RecruiteGraduates = formModel.RecruiteGraduates;
            jobPosition.Status = formModel.Status;
            jobPosition.StartDate = formModel.StartDate;
            jobPosition.EndDate = formModel.EndDate;
            jobPosition.Reposted = formModel.EndDate;

            return jobPosition;
        }
    }
}
